home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 132_01 / shoot.c < prev    next >
Text File  |  1985-08-19  |  4KB  |  205 lines

  1.     #INCLUDE    GRAPH.H
  2.     #INCLUDE    SHOOT.H
  3.     #ASM
  4.     ORG    4000H
  5.     LIST    -L
  6.     #ENDASM
  7.     #INCLUDE    PRELUDE
  8. /*
  9.     allocate list storage
  10. */
  11. int    master[NMASTER];
  12. int    lpage0[NPAGE],lpage1[NPAGE];
  13. int    toggle;    /* a toggle for page flipping */
  14. shoot()
  15. {
  16. int    *scrn,n,xr,yr,*object;
  17. int    *mscan;
  18. int    score;
  19. char    *prx,*pry;
  20.     prx = JOYRX;
  21.     pry = JOYRY;
  22.  
  23. *flop = 2;    /* clock interrupt counter = 2 */
  24. toggle = 0;
  25. score = 0;
  26. xr =1;
  27. yr = 1;
  28. init();        /* set up the graphics lists */
  29. while(1) {
  30.     if(firer())    {
  31.         remclk();
  32.         return;        /* exit */
  33.     }
  34. release(PLANE,PLNX0,PLNY0,VPLNX,0);
  35. while(posx(PLANE) < PLNXM){    /* until the plane runs off the screen */
  36.     xr = (*prx)*3 + GUNOFF;
  37.     release(GUN,xr,GUNY0,0,0);
  38.     move(PLANE);
  39.     if(blanked(BULLET)) { /* a bullet is not active */
  40.         if(firel()) {    /* if left fire button depressed */
  41.             release(BULLET,xr,(GUNY0 - 3),0,VBULY);
  42.         }
  43.     }
  44.     else {    /* a bullet is active */
  45.         move(BULLET);
  46.         if(hit(BULLET,PLANE)) {
  47.             blank(BULLET);
  48.             score++;
  49.             replace(PLANE,BOOM);
  50.             display();
  51.             *flop = 60; /* delay time for boom display */
  52.             while(*flop);
  53.             replace(BOOM,PLANE);
  54.             release(PLANE,PLNX0,PLNY0,VPLNX,0);
  55.         }
  56.         if(posy(BULLET) < PLNY0) blank(BULLET);
  57.     }
  58.     display();
  59.      }
  60.   }
  61. }
  62. display()    /* display the next page */
  63. {
  64.     if(toggle) {
  65.         cwriter(UPPG0,master,lpage0,PAGE0);
  66.         toggle = 0;
  67.         while(*flop != NULL); /* wait for page flip time */
  68.         *flop = NTICKS;
  69.         setscrn(PAGE0);
  70.     }
  71.     else {
  72.         cwriter(UPPG1,master,lpage1,PAGE1);
  73.         toggle = 1;
  74.         while(*flop != NULL);
  75.         *flop = NTICKS;
  76.         setscrn(PAGE1);
  77.     }
  78. }
  79. release(objnum,x,y,vx,vy) /* set object in position with velocity */
  80. int    objnum,x,y,vx,vy;
  81. {
  82. int    *loc;
  83.     if((loc=locate(master,objnum))==NULL) return(-1);/* error */
  84.     loc[X]=x;
  85.     loc[Y]=y;
  86.     loc[XINCR]=vx;
  87.     loc[YINCR]=vy;
  88.     loc[FLAGS] = MOVER | UPALL;
  89.     return(NULL);
  90. }
  91. move(objnum)    /* move the specified object */
  92. int    objnum;
  93. {
  94. int    *loc;
  95.     if((loc=locate(master,objnum))==NULL) return(-1);
  96.     loc[X]= loc[X] + loc[XINCR];
  97.     loc[Y] = loc[Y] + loc[YINCR];
  98.     loc[FLAGS] = loc[FLAGS] | UPALL;
  99. }
  100. firel()    /* test the state of left fire button. Return 1 if on */
  101. {
  102. char    *pstate;
  103.     pstate = SWPORT;
  104.     if(((*pstate)&SWTR) != NULL) return(NULL);
  105.     else      return(1);
  106. }
  107. firer()
  108. {
  109. char    *pstate;
  110.     pstate = SWPORT;
  111.     if(((*pstate)&SWTL) != NULL) return(NULL);
  112.     else    return(1);
  113. }
  114. blank(objnum)    /* turn off (blank) an object */
  115. int    objnum;
  116. {
  117. int     *loc;
  118.     if((loc=locate(master,objnum)) == NULL) return(-1);
  119.     loc[FLAGS] = BLANKED | UPALL;
  120.     return(NULL);
  121. }
  122. blanked(objnum)    /* TESTS for object blanked */
  123. int    objnum;
  124. {
  125. int    *loc;
  126.     if((loc=locate(master,objnum)) == NULL)return(1);
  127.     return((loc[FLAGS])&BLANKED);
  128. }
  129. posx(objnum)
  130. int    objnum;
  131. {
  132. int    *loc;
  133.     if((loc=locate(master,objnum)) == NULL)return(-1);
  134.     return(loc[X]);
  135. }
  136. posy(objnum)
  137. int    objnum;
  138. {
  139. int    *loc;
  140.     if((loc=locate(master,objnum)) == NULL) return(-1);
  141.     return(loc[Y]);
  142. }
  143. hit(proj,targ)
  144. int    proj,targ;
  145. {
  146. int    *pproj,*ptarg;
  147.     if((pproj=locate(master,proj)))
  148.         if((ptarg=locate(master,targ))) {
  149.             return(overlap(pproj,ptarg));
  150.         }
  151.     return(NULL);
  152. }
  153. replace(oldobj,newobj)    /* change the displayed object to the selected one */
  154. int    oldobj,newobj;
  155. {
  156. int    *from,*to;
  157.     if((from=locate(master,oldobj)))
  158.         if((to=locate(master,newobj))){
  159.             from[FLAGS]=BLANKED | UPALL ;
  160.             to[FLAGS] = UPALL;
  161.             to[X]=from[X];
  162.             to[Y]=from[Y];
  163.             to[XINCR]=from[XINCR];
  164.             to[YINCR]=from[YINCR];
  165.             return(NULL);
  166.         }
  167.     return(-1);
  168. }
  169. locate(plist,objnum)
  170. int    *plist,objnum;
  171. {
  172.     while(plist[FORWARD] != NULL) {
  173.         if(plist[NUMBER] != objnum) {
  174.             plist = plist[FORWARD];
  175.         }
  176.         else    return(plist);
  177.     }
  178.     return(NULL);
  179. }
  180. cwriter(upflag,mlist,page,screen)
  181. int    upflag,*mlist,*page,*screen;
  182. {
  183.  
  184.  
  185.     pass0(upflag,mlist,page,screen);
  186.     pass2(mlist,page,screen);
  187. }
  188.     #INCLUDE    shootini.c
  189.     #INCLUDE    SHOOT.GPH
  190.     #ASM
  191.     ORG    05C00H
  192.     #ENDASM
  193.     #INCLUDE    fpass0.c
  194.     #INCLUDE    fpass1.c
  195.     #INCLUDE    fpass2.c
  196.     #INCLUDE    LIB
  197.     #INCLUDE    RUN
  198.     #ASM
  199.     LIST    *
  200.     #ENDASM
  201. *
  202.     #ENDASM
  203. ASM
  204. ╚═$═ï$├à$>2è$╔>├ü$:è$╖O≥í$µ2Ç$2è$O
  205. ═┌$~